package com.atguigu.gmall.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 秒杀相关的交换机和队列绑定的创建
 */
@Configuration
public class SeckillRabbitConfig {
    /**
     * 创建秒杀的交换机
     * @return
     */
    @Bean("seckillExchange")
    public Exchange seckillExchange() {
        return ExchangeBuilder.topicExchange("seckill_exchange").build();
    }

    /**
     * 创建秒杀的队列
     * @return
     */
    @Bean("seckillQueue")
    public Queue seckillQueue() {
        return QueueBuilder.durable("seckill_queue").build();
    }

    /**
     * 创建秒杀的绑定
     * @param seckillExchange
     * @param seckillQueue
     * @return
     */
    @Bean
    public Binding seckillQinding(@Qualifier("seckillExchange") Exchange seckillExchange,
                           @Qualifier("seckillQueue") Queue seckillQueue) {
        return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckill.#").noargs();
    }

//    /**
//     * 创建秒杀的死信队列
//     * @return
//     */
//    @Bean("seckillNormalQueue")
//    public Queue seckillNormalQueue() {
//        return QueueBuilder.durable("seckill_normal_queue").build();
//    }
//
//    /**
//     * 创建绑定
//     * @param seckillExchange
//     * @param seckillNormalQueue
//     * @return
//     */
//    @Bean
//    public Binding seckillNormalQinding(@Qualifier("seckillExchange") Exchange seckillExchange,
//                                  @Qualifier("seckillNormalQueue") Queue seckillNormalQueue) {
//        return BindingBuilder.bind(seckillNormalQueue).to(seckillExchange).with("seckill.#").noargs();
//    }

}
